package com.jin10.util;

import cn.hutool.core.date.DateUtil;

import java.util.*;

/**
 * @author raofy
 * @date 2022-02-22 15:33
 * @desc
 */
public class KeyWordReplace {

    private final static String CURRENT_MONTH = "【当前月】";
    private final static String FIRST_VALUE = "【前值】";
    private final static String ACTUAL_VALUE = "【实际值】";
    private final static String FORECAST_VALUE = "【预测值】";
    private final static String MONTH_ON_MONTH_GROWTH = "【环比增幅】";
    private final static String YEAR_ON_YEAR_GROWTH = "【同比增幅】";
    private final static String YEAR_ON_YEAR_BASIC = "【同比】";

    public static String returnValue(String title) {
        return returnValue(title, 0, 0, 0, 0, 0, 0);
    }

    public static  String returnValue(String title, float firstValue, float actualValue, float forecastValue) {
        return returnValue(title, firstValue, actualValue, forecastValue, 0, 0, 0);
    }

    public static String returnValue(String title, float firstValue, float actualValue, float forecastValue, float monthOnMonthValue, float yearOnYearValue, float yearOnYearBasic) {
        if (title.contains(CURRENT_MONTH)) {
            title = replaceCurrentMonth(title);
        }
        if (title.contains(FIRST_VALUE)) {
            title = replaceFirstValue(title, firstValue);
        }
        if (title.contains(ACTUAL_VALUE)) {
            title = replaceActualValue(title, actualValue);
        }
        if (title.contains(FORECAST_VALUE)) {
            title = replaceForcastValue(title, forecastValue);
        }
        if (title.contains(MONTH_ON_MONTH_GROWTH)) {
            title = replaceMonthOnMonthGrowth(title, monthOnMonthValue);
        }
        if (title.contains(YEAR_ON_YEAR_GROWTH)) {
            title = replaceYearOnYearGrowth(title, yearOnYearValue);
        }
        if (title.contains(YEAR_ON_YEAR_BASIC)) {
            title = replaceYearOnYeatBasic(title, yearOnYearBasic);
        }
        return title;

    }

    public static String replaceCurrentMonth(String title) {
        int month = DateUtil.date().month();
        if (month == 0) {
            return title.replace(CURRENT_MONTH, "12月");
        }
        return title.replace(CURRENT_MONTH, month + "月");
    }

    public static String replaceFirstValue(String title, float firstValue) {
        return title.replace(FIRST_VALUE, String.valueOf(firstValue));
    }

    public static String replaceActualValue(String title, float firstValue) {
        return title.replace(ACTUAL_VALUE, String.valueOf(firstValue));
    }

    public static String replaceForcastValue(String title, float firstValue) {
        return title.replace(FORECAST_VALUE, String.valueOf(firstValue));
    }
    public static String replaceMonthOnMonthGrowth(String title, float firstValue) {
        return title.replace(MONTH_ON_MONTH_GROWTH, String.valueOf(firstValue));
    }
    public static String replaceYearOnYearGrowth(String title, float firstValue) {
        return title.replace(YEAR_ON_YEAR_GROWTH, String.valueOf(firstValue));
    }
    public static String replaceYearOnYeatBasic(String title, float firstValue) {
        return title.replace(YEAR_ON_YEAR_BASIC, String.valueOf(firstValue));
    }
}
